<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="远程协商"></uni-navbar></view>

		<view class="container">
			<u-row class="link-box" gutter="0" align="top">
				<u-col span="3" v-if="$sysMenus('ycxs_edit')">
					<navigator hover-class="none" class="link-item" url="/pagesB/negotiate/add">
						<image src="/static/img/icon_54.png" mode="aspectFill"></image>
						发起会议
					</navigator>
				</u-col>
				<u-col span="3">
					<navigator hover-class="none" class="link-item" url="/pagesB/negotiate/list?type=1">
						<image src="/static/img/icon_51.png" mode="aspectFill"></image>
						待开会议
					</navigator>
				</u-col>
				<u-col span="3">
					<navigator hover-class="none" class="link-item" url="/pagesB/negotiate/list">
						<image src="/static/img/icon_52.png" mode="aspectFill"></image>
						会议列表
					</navigator>
				</u-col>
			</u-row>

			<view class="list-box">
				<view class="filter-inner">
					<view class="filter-btn" :class="filterType == 0 ? 'active' : ''" @click="type(0)">
						<image src="/static/img/icon_11.png" mode="widthFix"></image>
						<image src="/static/img/icon_11_f.png" mode="widthFix"></image>
						我的远程会议
					</view>
					<view class="filter-btn" :class="filterType == 1 ? 'active' : ''" @click="type(1)">
						<image src="/static/img/icon_10.png" mode="widthFix"></image>
						<image src="/static/img/icon_10_f.png" mode="widthFix"></image>
						协商议事
					</view>
				</view>

				<view class="list-info_01" v-for="(item, index) of negotiateList" :key="item.id" @click="navTo(item)">
					<view class="info-title clamp">{{ item.roomName }}</view>
					<view class="info-btm">
						<view class="btm-left clamp">
							<text class="left-name">{{ item.createByName }}</text>
							<text class="left-time">{{ item.hopeStartTime }}</text>
						</view>
						<view class="btm-right">
							<view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ statusMap[item.nodeStatus] }}</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="loading" />
			</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			colorMap: {
				1: '#303133',
				2: '#0099ff',
				3: '#ff9900',
				9: '#19be6b'
			},
			statusMap: {
				1: '未开始',
				2: '进行中',
				3: '结束',
				9: '撤销'
			},
			filterType: 0,
			keyword: '',
			negotiateList: [],

			ycxsHstRoom: {
				nodeStatus: '',
				status: 1,
				roomName: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
				this.userName = this.userInfo.username;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				roleCodes: this.roleCodes,
				ycxsHstRoom: this.ycxsHstRoom
			};
			let url = '/haoshitong/list';
			if (this.filterType == 0) {
				url = '/haoshitong/myList';
			}
			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.negotiateList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.negotiateList = this.negotiateList.concat(res.data.records);
				this.loaded = true;
				if (this.negotiateList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		navTo(item) {
			if (this.filterType == 0) {
				if (item.nodeStatus == 2) {
					let parm = item.syncId + ',' + item.password + ',' + this.userName;
					WebviewClient.sendMessage('startVideoMeeting', parm);
					return false;
				}
			}
			uni.navigateTo({
				url: '/pagesB/negotiate/detail?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	border-radius: 30rpx;
	background-color: #fff;
}

.list-info_02 {
	.info-time {
		margin-top: 10rpx;
	}
}
</style>
